import base64
from exception import JsonException
import time
from time import struct_time
from fastapi import HTTPException
from model import db
from model.user import User

def decode(token:str="")->User|JsonException:
    if not token:
        return JsonException("token错误", 401)
    
    one = None
    try:
        with db.Session() as session:

            one = session.query(User).filter(
                User.token == token
            ).first()
    except Exception as e:
        print(e)
        return JsonException("token解析错误m", 401)

    if one == None:
        return JsonException("token错误n", 401)
    
    return one
